package io.linfeng.api.app.im.controller;

import io.linfeng.api.app.guest.response.GuestResponse;
import io.linfeng.api.app.im.reponse.MessageRecordResponse;
import io.linfeng.api.app.im.request.MessageRecordRequest;
import io.linfeng.api.app.moment.request.MomentRequest;
import io.linfeng.common.annotation.Login;
import io.linfeng.common.annotation.LoginUser;
import io.linfeng.common.api.R;
import io.linfeng.common.api.Result;
import io.linfeng.common.utils.StringUtil;
import io.linfeng.service.im.entity.SocketMsg;
import io.linfeng.service.im.server.MessageRecordService;
import io.linfeng.service.user.entity.UserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.apache.catalina.User;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.net.Socket;
import java.util.List;

/**
 * @author RJF
 * @date create at 2024-05-2024/5/11-15:36
 * copyright @2024 China Automotive Technology & Research Center Co.Ltd
 */
@RestController
@RequestMapping("/app/messageRecord")
@Api(tags = "消息记录API")
public class MessageRecordController {

    @Resource
    private MessageRecordService messageRecordService;

    /**
     * 通过发送者，接收者查询历史消息
     */
    @Login
    @PostMapping("/getMessage")
    @ApiOperation("历史聊天记录")
    public Result getMessage(@RequestBody MessageRecordRequest request) {
        if (StringUtil.isEmpty(request.getReceiveUserId()) || StringUtil.isEmpty(request.getSendUserId())) {
            return new Result<>().error();
        }
        List<MessageRecordResponse> messages = messageRecordService.getMessage(request);
        return new Result<List<MessageRecordResponse>>().ok(messages);
    }
}
